package com.google.code.alpaca.prototype.handler;

import javax.inject.Inject;

import net.customware.gwt.dispatch.server.ActionHandler;
import net.customware.gwt.dispatch.server.ExecutionContext;
import net.customware.gwt.dispatch.shared.DispatchException;

import com.google.code.alpaca.prototype.dao.MessageDAO;
import com.google.code.alpaca.prototype.rpc.MessageActions.SaveMessageAction;
import com.google.code.alpaca.prototype.rpc.VoidResult;
import com.google.inject.persist.Transactional;

public class SaveMessageHandler implements
		ActionHandler<SaveMessageAction, VoidResult> {

	@Inject
	private MessageDAO messageRepository;

	@Override
	public Class<SaveMessageAction> getActionType() {
		return SaveMessageAction.class;
	}

	@Transactional
	@Override
	public VoidResult execute(SaveMessageAction action, ExecutionContext context)
			throws DispatchException {
		messageRepository.create(action.get());
		return VoidResult.VOID;
	}

	@Override
	public void rollback(SaveMessageAction action, VoidResult result,
			ExecutionContext context) throws DispatchException {
	}

}
